package com.fimuz.mqmeet.api.login.control;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fimuz.mqmeet.api.login.service.LoginService;
import com.fimuz.mqmeet.api.login.service.model.SubmitSpModel;
import com.fimuz.mqmeet.api.login.service.model.SubmitSrModel;
import com.fosun.spr.core.base.CoBaseControl;
import com.fosun.spr.core.utils.SessionUtils;

@Controller
public class LoginControl extends CoBaseControl {
	//@Autowired
	@Resource
	private LoginService loginService;

	/**
	 * http://127.0.0.1:8080/mq_meet_server/api/login/submit
	 * {"userName":"chenshiming0802@163.com","password":"123123"}
	 * @param request
	 * @param spModel
	 * @return
	 */
	@RequestMapping(value = "/api/login/submit",method = RequestMethod.POST) 
	public SubmitSrModel submit(HttpServletRequest request,@RequestBody SubmitSpModel spModel) {
		SubmitSrModel srModel = loginService.submit(spModel);
		//如果登录成功，则写Session 
		if("1".equals(srModel.getLoginResult())){			
			String token = SessionUtils.set(request, srModel.getUserId(), srModel.getTeamId());
			srModel.setToken(token);
		}
		return srModel; 
	}
}
